package com.jiashihui.schema_lgorithm.schema.template_method;

/**
 * @author jiashihui
 * @describe: 计算抽象类
 * @date 2019/03/14
 */
public abstract class AbstractCalculator {

    /**
     * 主方法，实现对本类其他方法的调用
     *
     * @author jiashihui
     */
    public final int calculate(String exp, String opt) {
        int array[] = split(exp, opt);
        return calculate(array[0], array[1]);
    }

    /**
     * 计算两个数字
     *
     * @author jiashihui
     */
    abstract public int calculate(int num1, int num2);

    /**
     * 处理分隔
     *
     * @author jiashihui
     */
    public int[] split(String exp, String opt) {
        String array[] = exp.split(opt);
        int arrayInt[] = new int[2];
        arrayInt[0] = Integer.parseInt(array[0]);
        arrayInt[1] = Integer.parseInt(array[1]);
        return arrayInt;
    }

}
